package com.uni.sofia.reader.utils.test
{
	import com.uni.sofia.reader.magazine.Magazine;
	import com.uni.sofia.reader.utils.MagazineBuilder;
	
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.xml.XMLDocument;
	
	import flexunit.framework.Assert;
	
	import mx.controls.Alert;
	import mx.utils.OnDemandEventDispatcher;
	
	import org.flexunit.asserts.assertEquals;
	import org.flexunit.asserts.assertNull;
	
	public class MagazineBuilderTest
	{		
		private var magazineXML:XML;
	
		[Before]
		public function setUp():void
		{	
			magazineXML =
				<magazine>
				   <name>NY Times</name>
				   <publisher>Amazon</publisher>
				   <year>2019</year>
				   <month>4</month>
				   <day>15</day>
				   <pages>
					 <page>
					   <number>1</number>
					   <image>time.jpg</image>
					   <description>dummy desription</description>
					 </page>
					 <page>
					   <number>2</number>
					   <image>time.jpg</image>
					   <description>first page</description>
					 </page>
					 <page>
					   <number>3</number>
					   <image>time.jpg</image>
					   <description>second page</description>
					 </page>
					 <page>
					   <number>4</number>
					   <image>time.jpg</image>
					   <description>last page</description>
					 </page>
				   </pages>
				</magazine>;
		}
		
		[Test]
		public function buildNullMagazine():void
		{
			assertNull(MagazineBuilder.loadMagazine(null));
		}
		
		[Test]
		public function checkPublisherOfMagazine():void
		{
			var magazine:Magazine = MagazineBuilder.loadMagazine(magazineXML);
			assertEquals("Amazon", magazine.publisher);
		}
		
		[Test]
		public function checkNameOfMagazine():void
		{
			var magazine:Magazine = MagazineBuilder.loadMagazine(magazineXML);
			assertEquals("NY Times", magazine.name);
		}
		
		[Test]
		public function checkReleaseDateOfMagazine():void
		{
			var magazine:Magazine = MagazineBuilder.loadMagazine(magazineXML);
			assertEquals(new Date("2019", "04", "15").time, magazine.released.time);
		}
		
		[Test]
		public function checkNumberOfPagesOfMagazine():void
		{
			var magazine:Magazine = MagazineBuilder.loadMagazine(magazineXML);
			assertEquals(4, magazine.pages.length);
		}
		
		
		
	}
}